package com.demo.project.djy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.demo.framework.aspectj.lang.annotation.Log;
import com.demo.framework.aspectj.lang.enums.BusinessType;
import com.demo.project.djy.domain.ConXsjkhzb;
import com.demo.project.djy.service.IConXsjkhzbService;
import com.demo.framework.web.controller.BaseController;
import com.demo.framework.web.domain.AjaxResult;
import com.demo.common.utils.poi.ExcelUtil;
import com.demo.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
/**
 * 产品月度统计Controller
 * 
 * @author demo
 * @date 2025-03-28
 */
@RestController
@RequestMapping("/djy/xsjkhzb")
public class ConXsjkhzbController extends BaseController
{
    @Autowired
    private IConXsjkhzbService conXsjkhzbService;

    /**
     * 查询产品月度统计列表
     */
    @PreAuthorize("@ss.hasPermi('djy:xsjkhzb:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConXsjkhzb conXsjkhzb)
    {
        startPage();
        List<ConXsjkhzb> list = conXsjkhzbService.selectConXsjkhzbList(conXsjkhzb);
        return getDataTable(list);
    }

    /**
     * 导出产品月度统计列表
     */
    @PreAuthorize("@ss.hasPermi('djy:xsjkhzb:export')")
    @Log(title = "产品月度统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConXsjkhzb conXsjkhzb)
    {
        List<ConXsjkhzb> list = conXsjkhzbService.selectConXsjkhzbList(conXsjkhzb);
        ExcelUtil<ConXsjkhzb> util = new ExcelUtil<ConXsjkhzb>(ConXsjkhzb.class);
        util.exportExcel(response, list, "产品月度统计数据");
    }

    /**
     * 获取产品月度统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('djy:xsjkhzb:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(conXsjkhzbService.selectConXsjkhzbById(id));
    }

    /**
     * 新增产品月度统计
     */
    @PreAuthorize("@ss.hasPermi('djy:xsjkhzb:add')")
    @Log(title = "产品月度统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConXsjkhzb conXsjkhzb)
    {
        String operName = getUsername();
        conXsjkhzb.setCreateBy(operName);
        conXsjkhzb.setUpdateBy(operName);
        String msg = conXsjkhzbService.insertConXsjkhzb(conXsjkhzb);
        if (msg.length() > 0){
            return error(msg);
        }
        return success("新增成功");
    }

    /**
    * 导入产品月度统计
    */
    @PreAuthorize("@ss.hasPermi('djy:xsjkhzb:import')")
    @Log(title = "产品月度统计", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<ConXsjkhzb> util = new ExcelUtil<ConXsjkhzb>(ConXsjkhzb.class);
        List<ConXsjkhzb> conXsjkhzbList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String msg = conXsjkhzbService.insertConXsjkhzbs(conXsjkhzbList, operName);
        if (msg.length() > 0){
            return error(msg);
        }
        return success("导入成功");
    }

    /**
     * 修改产品月度统计
     */
    @PreAuthorize("@ss.hasPermi('djy:xsjkhzb:edit')")
    @Log(title = "产品月度统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConXsjkhzb conXsjkhzb)
    {
        String operName = getUsername();
        conXsjkhzb.setUpdateBy(operName);
        String msg = conXsjkhzbService.updateConXsjkhzb(conXsjkhzb);
        if (msg.length() > 0){
            return error(msg);
        }
        return success("修改成功");
    }

    /**
     * 删除产品月度统计
     */
    @PreAuthorize("@ss.hasPermi('djy:xsjkhzb:remove')")
    @Log(title = "产品月度统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        String msg = conXsjkhzbService.deleteConXsjkhzbByIds(ids);
        if (msg.length() > 0){
            return error(msg);
        }
        return success("删除成功");
    }

    /**
    * 产品月度统计模板下载
    */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<ConXsjkhzb> util = new ExcelUtil<>(ConXsjkhzb.class);
        util.importTemplateExcel(response, "产品月度统计数据");
    }
}
